package Arrayexer;

/**
 * 属性： 学校名称(school)，班级名称(name)座位数(seating)
 * 
 * @author AcerMr
 *
 */
public class ClassAndGrade
{
	String school;
	String name;
	int seating;
	Students stu[] = new Students[3];
	private int pointer = 0;
	private int step = 2;

	public ClassAndGrade()
	{

	}

	public ClassAndGrade(String school, String name, int seating)
	{
		this.school = school;
		this.name = name;
		this.seating = seating;
	}

	public String toString()
	{
		String reault = "学校名字：" + school + "；班级名字：" + name + "；届次：" + seating + "；";
		return reault;
	}

	public String getSchool()
	{
		return school;
	}

	public void setSchool(String school)
	{
		this.school = school;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public int getSeating()
	{
		return seating;
	}

	public void setSeating(int seating)
	{
		this.seating = seating;
	}
	public int shuliang() 
	{
		return pointer;
	}
	public boolean creat(Students stud)
	{
		try
		{
			stu[pointer] = stud;
			pointer++;
			kuochong();
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		return false;
	}

	public boolean creat(int index, Students stud)
	{
		for (int i = pointer; i >= index; i--)
		{
			stu[i + 1] = stu[i];
		}
		stu[index] = stud;
		pointer++;
		kuochong();
		return false;
	}
	public boolean Update(int index,Students stud)
	{
		if(index<0||index>pointer)
		{
			System.out.println("大哥没有这个下标");
			return false;
		}
		stu[index] = stud;
		return true;
	}
	public Students Deleat(int index) 
	{
		Students teamp = this.stu[index];
		for(int i = index ; i < stu.length; i++) 
		{
			stu[i] = stu[i+1];
		}
		pointer--;
		return teamp;
		
	}
	private void kuochong()
	{
		if (pointer == stu.length)
		{
			Students[] newstu = new Students[pointer + step];
			for (int i = 0; i < pointer; i++)
			{
				newstu[i] = stu[i];
			}
			stu = newstu;
		}
	}

	public void Retrieve()
	{
		for (int i = 0; i < pointer; i++)
		{
			System.out.println(stu[i]);
		}
	}
}
